package com.sasu.university_data.service.impl;


import com.sasu.university_data.entity.Score;
import com.sasu.university_data.mapper.ScoreMapper;
import com.sasu.university_data.service.ScoreService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("scoreService")
public class ScoreServiceImpl implements ScoreService {
    @Resource
    private ScoreMapper scoreMapper;

    @Override
    public List<Score> queryById( Integer id) {
        return scoreMapper.queryById(id);
    }

    @Override
    public long count (Integer id) {
        return scoreMapper.count(id);
    }

    @Override
    public List<Score> selectByPage (Integer id, Integer page, Integer pageSize ) {
        if(page<=1) {
            page = 1;
        }
        if(pageSize<=0) {
            pageSize = 10;
        }
        return scoreMapper.selectByPage(id,(page - 1) * pageSize, pageSize);
    }

    /**
     * 新增数据
     *
     * @param score 实例对象
     * @return 是否成功
     */
    @Override
    public boolean insert(Score score){
        int flag = scoreMapper.insert(score);
        return flag > 0;
    }

    /**
     * 更新数据
     *
     * @param score 实例对象
     * @return 是否成功
     */
    @Override
    public boolean update(Score score){
        int flag = scoreMapper.update(score);
        return flag > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id){
        int flag = scoreMapper.deleteById(id);
        return flag > 0;
    }

    /***
     * 通过id批量删除
     * @param ids
     * @return
     */
    @Override
    public boolean deleteByIds ( int[] ids ) {
        int flag = scoreMapper.deleteByIds(ids);
        return flag>0;
    }

}
